package com.aichan.aibi.controller;

import com.aichan.aibi.common.BaseResponse;
import com.aichan.aibi.common.DeleteRequest;
import com.aichan.aibi.model.dto.chart.ChartAddRequest;
import com.aichan.aibi.model.dto.chart.ChartQueryRequest;
import com.aichan.aibi.model.dto.chart.ChartUpdateRequest;
import com.aichan.aibi.model.dto.ai.GenChartRequest;
import com.aichan.aibi.model.entity.Chart;
import com.aichan.aibi.model.vo.ChartGenResult;
import com.aichan.aibi.service.ChartService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author: mengyu
 * @Date: 2024/11/16
 */
@RestController
@RequestMapping("/chart")
@Slf4j
@Tag(name = "ChartController")
public class ChartController {
    @Resource
    private ChartService chartService;

    @PostMapping("/add")
    public BaseResponse<Boolean> addChart(@RequestBody ChartAddRequest chartAddRequest) {
        chartService.addChart(chartAddRequest);
        return BaseResponse.ok(true);
    }

    @PutMapping("/update")
    public BaseResponse<Boolean> updateChart(@RequestBody ChartUpdateRequest chartUpdateRequest) {
        chartService.updateChart(chartUpdateRequest);
        return BaseResponse.ok(true);
    }

    @DeleteMapping("/delete")
    public BaseResponse<Boolean> deleteChart(@RequestBody DeleteRequest deleteRequest) {
        chartService.deleteChart(deleteRequest);
        return BaseResponse.ok(true);
    }

    @PostMapping("/page/chart")
    public BaseResponse<Page<Chart>> getChartPage(@RequestBody ChartQueryRequest chartQueryRequest) {
        Page<Chart> page = chartService.getChartPage(chartQueryRequest);
        return BaseResponse.ok(page);
    }

    @PostMapping("/aiGen")
    @Tag(name = "genResultFormUserDataByAI")
    public BaseResponse<ChartGenResult> genResultFormUserDataByAI(@RequestPart("file") MultipartFile multipartFile,
                                                                  GenChartRequest genChartRequest) {
        ChartGenResult result = chartService.genResultFormUserDataByAI(multipartFile, genChartRequest);
        return BaseResponse.ok(result);
    }


}
